#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const ll p = 1e9 + 7;

struct matrix {
	ll c[4][4];
	matrix() { memset(c, 0, sizeof c); }
}F,A;

matrix operator*(matrix& a, matrix& b) {
	matrix t;
	for (int i = 1; i <= 3; i++) {
		for (int j = 1; j <= 3; j++) {
			for (int k = 1; k <= 3; k++) {
				t.c[i][j] = (t.c[i][j] + a.c[i][k] * b.c[k][j]) % p;
				t.c[i][j] %= p;
			}
		}
	}
	return t;
}

void qpow(ll n) {
	F.c[1][1] = F.c[1][2] = F.c[1][3] = 1;
	memset(A.c, 0, sizeof(A.c));
	A.c[1][1] = A.c[1][2] = A.c[2][3] = A.c[3][1] = 1;
	while (n) {
		if (n & 1) F = F * A;
		A = A * A;
		n >>= 1;
	}
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		ll n; cin >> n;
		if (n <= 3) {
			cout << 1 << endl;
			continue;
		}
		qpow(n - 3);
		cout << F.c[1][1] << endl;
	}
	return 0;
}